<?php
$section = 7;
include("includes/secure.php");
include("../includes/config.php");
include("../includes/class/school.class.php");
require_once("../includes/fckeditor/fckeditor_php5.php");
require_once("../includes/class/fileManagement.class.php");

$school = new School(); 
$file = new fileManagement();

$desc_es1 = new FCKeditor('descripcion');
	//$desc_es->ToolbarSet = "Basic";
	$desc_es1->ToolbarSet = "Default";
	$desc_es1->Height = "250";
	$desc_es1->Width = "750";
	

$codeSound =$_GET['code'];
		
		
if(isset($_POST['edit']) && $_POST['edit'] == 1)
{
	$new_data->codeSound	= $_POST['codeSound'];
	$new_data->fecha 		= cambiarFormatoFecha($_POST['fecha'],2);
	$new_data->school    	= mysql_real_escape_string($_POST['school']);
	$new_data->tittle	    = mysql_real_escape_string($_POST['title']);
	$new_data->description	= mysql_real_escape_string($_POST['descripcion']);
	
		
	if(isset($_FILES['archivo']))
	{
		for($i=0;$i<sizeof($_FILES['archivo']['tmp_name']);$i++)
		{
			if(is_uploaded_file($_FILES['archivo']['tmp_name'][$i]))
			{
				$documento = $file->subirArchivo($_FILES['archivo']['tmp_name'][$i],$_FILES['archivo']['name'][$i],'../file_upload/documentos/');								 
				$new_data->original 	= $_FILES['archivo']['name'][$i];
				$new_data->renam        = $documento;
				@unlink("../file_upload/documentos/".$_POST['soundRenam']);							
			}
			
		}
	}
	
	if($school->editSound($new_data))
	{	
		$school->deleteDevelopments($new_data->codeSound);
		$exito = true;
			
			$members =  explode(",",$_POST['members']);
									
			for($i=0;$i<count($members);$i++)
			{	
				
				$dataMember->name 		= $members[$i];
				$dataMember->sound 	= $id;
				
				if(!$school->addDeveloment($dataMember))
				{
					$exito = false;
				}
			}	
			if($exito)
			{
				echo "<script>alert('Audio modificado con éxito')</script>";
				echo "<script>window.location.href='listSounds.php';</script>";	
			}
			else
			{
				echo "<script>alert('El Audio no se pudo modificar')</script>";
				echo "<script>window.location.href='listSounds.php';</script>";	
			}	
		
	}
	else
	{
		echo "<script>alert('El Audio no se pudo modificar')</script>";
				echo "<script>window.location.href='listSounds.php';</script>";	
	}
	
}
else
{
	$dataSound = $school->getDataSound($codeSound);
	$stringSchool = $school->listSchoolSelect($dataSound->schoolName);
	$desc_es1->Value = $dataSound->description;
	$arreglo 	= $school->listEditDevelopment($codeSound); 
	
	$idMember	= '';
	$indice		= 0;
	$ind		= '';
	
	 $listMember= $school->getDataDevelopment($codeSound);
	 for($i=0;$i<count($listMember);$i++)
	 {
	 	$idMember	.= "'".$listMember[$i]->mem_name."',";
		$ind		.= "'".$i."',";
	 }
	 $indice = $i;
	 
	 $idMember = substr($idMember,0,-1);	
	 $ind      = substr($ind,0,-1);	
}


?>
